<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use DB;
use App\Http\Requests;
use App\Http\Controllers\Controller;

class OrderController extends Controller
{
    //订单列表
    public function getIndex()
    {   
       // echo "订单列表页";
        //查询数据
        $orders = DB::table('order')->paginate(5);
        // dd($orders);
        return view('admin.order.index',['orders'=>$orders]);
    }

    //订单删除
    public function getDelete(Request $request){
    	$id = $request->only('id');
    	$res = DB::table('order')->where('id',$id)->where('dingdan_id','like','%'.$request->search.'%')->delete();
    	// dd($res);
    	if($res == 1){
    		echo 1;
    	}else{
    		echo 2;
    	}
    }
    //订单修改
    public function getUpdate($id)
    {
        // dd($id);
        $orders = DB::table('order')->where('id',$id)->first();
        return view('admin.order.edit',['orders'=>$orders]);
    }

    //订单数据修改
    public function postSave(Request $request)
    {
        $data = $request->only('dingdan_id','price','utname','status');
        $data['dingdan_size'] = $request->input('size')[0];
        $data['dingdan_color'] = $request->input('color')[0];
        $id = $request->only('id');
        // dd($id);
       // dd($data);
        $res = DB::table('order')->where('id',$id)->update($data);
        if($res){
            return redirect('/admin/order/index');
        }else{
            return back();
        }

        
    }
}
